package com.service.weChatWifiLogin.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.service.config.utils.ExcelUtil;
import com.service.config.utils.Result;
import com.service.config.utils.UserTokenManager;
import com.service.weChatWifiLogin.dao.ShopInfoDao;
import com.service.weChatWifiLogin.dto.AddShopInfoDto;
import com.service.weChatWifiLogin.dto.CheckTenantDto;
import com.service.weChatWifiLogin.dto.NameListDto;
import com.service.weChatWifiLogin.dto.ShopInfoDto;
import com.service.weChatWifiLogin.entity.NameList;
import com.service.weChatWifiLogin.entity.ShopInfo;
import com.service.weChatWifiLogin.service.ShopInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

import static com.service.config.constant.Constant.*;

/**
 * 店铺表(ShopInfo)表控制层
 *
 * @author makejava
 * @since 2021-06-16 17:11:01
 */
@RestController
@RequestMapping("shopInfo")
@Api(tags = "店铺管理接口")
public class ShopInfoController {
    /**
     * 服务对象
     */
    @Resource
    private ShopInfoService shopInfoService;

    /**
     * 后台审核完毕，用户操作提交配置下发
     * @param shopInfoDto
     * @return
     */
    @ApiOperation(value = "店铺审核完毕,下发配置")
    @PostMapping(value = "/queryWeiUser")
    public Result updateShopInfo(@RequestBody ShopInfoDto shopInfoDto) {
        try {
           return shopInfoService.updateShopInfo(shopInfoDto);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    /**
     * 用户查询审核记录
     * @param shopId
     * @return
     */
    @ApiOperation(value = "用户查询审核记录")
    @PostMapping(value = "/queryRecordInfo")
    public Result queryRecordInfo(@RequestParam(value = "shopId") String shopId) {
        try {
            return shopInfoService.queryRecordInfo(shopId);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    /**
     * 管理员查询审核记录
     * @param shopId
     * @return
     */
    @ApiOperation(value = "管理员查询审核记录")
    @GetMapping(value = "/queryRecordInfo")
    public Result queryManageRecordInfo(@RequestParam(value = "shopId",required = false) @ApiParam("店铺id") String shopId,
                                        @RequestParam(value = "status",required = false) @ApiParam("true -- 审核成功 false--审核失败") Boolean status,
                                        @RequestParam(value = "startDate",required = false)  @ApiParam("开始日期")String startDate,
                                        @RequestParam(value = "endDate",required = false)  @ApiParam("结束日期")String endDate,
                                        @RequestParam(value = "pageSize") @ApiParam("条数") Integer pageSize ,
                                        @RequestParam(value = "pageNum") @ApiParam("页码") Integer pageNum) {
        try {
            return shopInfoService.queryManageRecordInfo(shopId,status,startDate,endDate,pageSize,pageNum);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    @PostMapping("checkApiAccount")
    @ApiOperation(value = "校验云管平台的账号和密码")
    @ResponseBody
    public Result checkTenant(@RequestBody CheckTenantDto checkTenantDto) {
        try {
            return shopInfoService.check(checkTenantDto);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }

    /**
     * boss端撤销审核
     * @param shopId
     * @return
     */
    @ApiOperation(value = "boss端撤销审核")
    @GetMapping(value = "/cancelShopInfoConfig")
    public Result cancelShopInfoConfig(@RequestParam(value = "shopId") String shopId) {
        try {
            return shopInfoService.cancelShopInfoConfig(shopId);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    /**
     * boss端立即回退
     * @param shopId
     * @return
     */
    @ApiOperation(value = "boss端立即回退")
    @GetMapping(value = "/returnShopInfoConfig")
    public Result returnShopInfoConfig(@RequestParam(value = "shopId") String shopId) {
        try {
            return shopInfoService.returnShopInfoConfig(shopId);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    /**
     * boss端修改之后，正式表的状态为审核中
     * @param shopInfoDto
     * @return
     */
    @ApiOperation(value = "boss端修改之后，提交审核，正式表的状态为审核中")
    @PostMapping(value = "/updateShopInfoConfig")
    public Result updateShopInfoConfig(@RequestBody ShopInfoDto shopInfoDto) {
        try {
            return shopInfoService.updateShopInfoConfig(shopInfoDto);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    @ApiOperation(value = "店铺列表")
    @GetMapping(value = "/queryShopInfo")
    public Result updateShopInfo(@RequestHeader(value = "token",required = false) @ApiParam("token令牌") String bAuthToken,
                                 @RequestParam(value = "bossId") String bossId) {
        try {
            return shopInfoService.queryByBossId(bAuthToken,bossId);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }

    @ApiOperation(value = "查询店铺配置信息")
    @GetMapping(value = "/queryShopInfoById")
    public Result queryShopInfoById(@RequestHeader(value = "token",required = false) @ApiParam("token令牌") String bAuthToken,
                                 @RequestParam(value = "shopId") String shopId,@RequestParam(value = "flag")@ApiParam("标识符 1--查询config表 2--查询old表") String flag) {
        try {
            return shopInfoService.queryShopInfoById(bAuthToken,shopId,flag);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    @ApiOperation(value = "店铺新增")
    @PostMapping(value = "/addShopInfo")
    public Result addShopInfo(@RequestBody AddShopInfoDto addShopInfoDto) {
        try {
            return shopInfoService.addShopInfo(addShopInfoDto);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
    /**
     * 下载顾客清单
     */
    @ApiOperation(value = "下载顾客清单")
    @GetMapping(value = "/download")
    public void download(HttpServletResponse response, HttpServletRequest request,@RequestParam(value = "shopId") String shopId) {
        shopInfoService.queryByShopId(response,request,shopId);
    }
    /**
     * 查看黑白名单
     */
    @ApiOperation(value = "查看黑白名单")
    @GetMapping(value = "/queryUserList")
    public Result queryUserList(@RequestParam(value = "shopId") String shopId,
                              @RequestParam(value = "type") Integer type) {
        return shopInfoService.queryUserList(shopId,type);
    }
    /**
     * 查看黑白名单
     */
    @ApiOperation(value = "配置黑白名单")
    @GetMapping(value = "/configUserList")
    public Result configUserList(@RequestParam(value = "shopId") String shopId,
                                @RequestParam(value = "type") Integer type) {
        return shopInfoService.configUserList(shopId,type);
    }
    /**
     * 删除店铺
     */
    @ApiOperation(value = "deleteShop 删除店铺")
    @GetMapping(value = "/deleteShop")
    public Result deleteShop(@RequestParam(value = "shopId") String shopId) throws Exception {
        try {
            return shopInfoService.deleteById(shopId);
        } catch (Exception e) {
            return Result.failure(1001, e.getMessage());
        }
    }
}
